%Calculate the Extended Affine Matrix of matrix A.
%
%Calculate the Extended Affine Matrix of matrix A where n is the degree of
%A and m is the degree of the state vector x in homogeneous form.
%
%Prototype: [newA] = extendedAffine(A, n, m, hState, d)
%
%Input:     A - nxn matrix with Syms affine parameters.
%           n - Degree of A.
%           m - Degree of the state vector x in homogeneous form.
%           hState - Homogeneous state vector.
%           d - Dimension of homogeneous state vector hState.
%
%Output:    newA - Extended Affine Matrix A divided in cells.

function [ newA ] = extendedAffine( A, n, m, hState, d )

[Ae] = extendedMatrix(A, n, m, hState);

kmax = 0;
paramName = findsym(A);
if strfind(paramName,',')
    paramName = strsplit(',',paramName);
else
    paramName = strsplit('',paramName);
end

for i = 0:length(paramName)
    for j = 1:length(paramName)
        if i ~= j
            eval(strcat(char(paramName(j)),'=0;'));
        else
            eval(strcat(char(paramName(j)),'=1;'));
        end
    end
    newA{i+1} = subs(Ae);
    if i~=0
        newA{i+1} = newA{i+1}-newA{1};
    end
end

return;

end
